angular.module('mamApp').controller('channelPlayOverviewController', ['$scope', '$state', 'DataManager','api','paramsManager',
    function ($scope, $state, DataManager, api, paramsManager) {

    $scope.search = {
        pageNo: $state.params.pageNo || 1,
        pageSize: $state.params.pageSize || 10,
        startTime: $state.params.startTime || "",
        endTime: $state.params.endTime || "",
        "X-Auth-Token":$scope.userInfo.token
    };

    $scope.paginationConf = {
        currentPage: $state.params.pageNo || 1,
        itemsPerPage: $state.params.pageSize || 10,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, $scope.search)
        }
    };

    //日期选择
    $scope.rangeDate = {
        startDate: $scope.search.startTime ? moment($scope.search.startTime).format('X') : null,
        endDate: $scope.search.endTime ? moment($scope.search.endTime).format('X') : null,
        onSelected: function (data, scope) {  //时间选择确认事件
            $scope.search.startTime = data.startDate ? moment(new Date(parseFloat(data.startDate) * 1000)).format("YYYY-MM-DD") : null;
            $scope.search.endTime = data.endDate ? moment(new Date(new Date(parseFloat(data.endDate) * 1000))).format("YYYY-MM-DD") : null;
            $scope.search.pageNo=1;
            $state.go($state.current.name, $scope.search);
        }
    };

    //下载
    $scope.downHref = api + "/admin/stat/play/category/export" + paramsManager.query($scope.search);

    //列表
    $scope.noPermission=false;
    DataManager.oneLevelChannelPlayList([$scope.search.pageNo, $scope.search.pageSize], $scope.search).then(function (result) {
        if(result.data.c=="n"){
            $scope.noPermission=true;
        }else{
            $scope.noPermission=false;
            $scope.oneLevelChannelPlayList = result.data.pageList;
            $scope.paginationConf.totalItems = result.data.total;
        }
    });




}]);

